package com.jumi.microservice.rocketmq;

import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.jumi.microservice.common.exception.GlobalExceptionHandler;
import com.jumi.microservice.config.RocketMqConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Description 生产者
 * @ClassName RocketMqProducer
 * @Author Abel Yang
 * @Date 2020/10/24/024 9:46
 **/
@Configuration
public class RocketMqProducer {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @Resource
    private RocketMqConfig rocketMqConfig;

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public ProducerBean buildProducer() {
        log.info("-----------Apache RocketMQ Producer creating ----------------------");
        ProducerBean producer = new ProducerBean();
        producer.setProperties(rocketMqConfig.getMqProperties());
        log.info("-----------Apache RocketMQ Producer created ----------------------");
        return producer;
    }
}
